﻿@using Nop.Plugin.Pricing.PreciousMetals
@using Nop.Web.Framework
@{
    Layout = "~/Administration/Views/Shared/_AdminPopupLayout.cshtml";
}
@model Nop.Plugin.Pricing.PreciousMetals.Models.PreciousMetalsDetailModel
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "preciousmetals-form" }))
{
    <script type="text/javascript">

        // since we are in an iframe, submit this form before the parent form's submit
        // this is done in a synchronous ajax call to prevent ui wierdness
        $('#productvariant-form', window.parent.document).submit(function () {
            $.ajax({
                type: 'POST',
                data: $('#preciousmetals-form').serialize(),
                async: false
            });
        });

        $(document).ready(function () {
            $("#@Html.FieldIdFor(model => model.Enabled)").click(togglePreciousMetals);
            togglePreciousMetals();
        });

        function togglePreciousMetals() {
            if (getE('@Html.FieldIdFor(model => model.Enabled)').checked) {
                $('#pnlPreciousMetalsMetalType').show();
                $('#pnlPreciousMetalsQuoteType').show();
                $('#pnlPreciousMetalsMathType').show();
                $('#pnlPreciousMetalsWeight').show();
                $('#pnlPreciousMetalsPercentMarkup').show();
                $('#pnlPreciousMetalsFlatMarkup').show();
                $('#pnlPreciousTierPriceType').show();
                $('#pnlPreciousMetalsMathType').show();
                $('#pnlPreciousMetalsLowerAmount').show();
                $('#pnlPreciousMetalsPriceRoundingType').show();
                $('#pnlPreciousMetalsPriceRounding').show();
                $('#pnlWeightType').show();
                window.parent.jQuery("iframe", top.document).height(380);
            }
            else {
                $('#pnlPreciousMetalsMetalType').hide();
                $('#pnlPreciousMetalsQuoteType').hide();
                $('#pnlPreciousMetalsMathType').hide();
                $('#pnlPreciousMetalsWeight').hide();
                $('#pnlPreciousMetalsPercentMarkup').hide();
                $('#pnlPreciousMetalsFlatMarkup').hide();
                $('#pnlPreciousTierPriceType').hide();
                $('#pnlPreciousMetalsMathType').hide();
                $('#pnlPreciousMetalsLowerAmount').hide();
                $('#pnlPreciousMetalsPriceRoundingType').hide();
                $('#pnlPreciousMetalsPriceRounding').hide();
                $('#pnlWeightType').hide();
                window.parent.jQuery("iframe", top.document).height(60);
            }
        }
        
    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Enabled):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Enabled)
                @Html.ValidationMessageFor(model => model.Enabled)
            </td>
        </tr>
        <tr id="pnlPreciousMetalsMetalType">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.MetalType):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.MetalType, ((PreciousMetalType)Model.MetalType).ToSelectList())
                @Html.ValidationMessageFor(model => model.MetalType)
            </td>
        </tr>
        <tr id="pnlPreciousMetalsQuoteType">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.QuoteType):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.QuoteType, ((PreciousMetalsQuoteType)Model.QuoteType).ToSelectList())
                @Html.ValidationMessageFor(model => model.QuoteType)
            </td>
        </tr>
        <tr id="pnlPreciousTierPriceType">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.TierPriceType):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.TierPriceType, ((PreciousMetalsTierPriceType)Model.TierPriceType).ToSelectList())
                @Html.ValidationMessageFor(model => model.TierPriceType)
            </td>
        </tr>
        <tr id="pnlPreciousMetalsLowerAmount">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LowerAmount):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LowerAmount) [@Model.BaseCurrencyIn]
                @Html.ValidationMessageFor(model => model.LowerAmount)
            </td>
        </tr>

        <tr id="pnlPreciousMetalsWeight">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Weight):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Weight)
                @Html.ValidationMessageFor(model => model.Weight) 
            </td>
        </tr>
        <tr id="pnlWeightType">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.WeightId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.WeightId, Model.AvailableWeights)
                @Html.ValidationMessageFor(model => model.WeightId)
            </td>
        </tr>
        <tr id="pnlPreciousMetalsMathType">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.MathType):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.MathType, ((PreciousPriceCalculationType)Model.MathType).ToSelectList())
                @Html.ValidationMessageFor(model => model.MathType)
            </td>
        </tr>
        <tr id="pnlPreciousMetalsPercentMarkup">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.PercentMarkup):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.PercentMarkup) %
                @Html.ValidationMessageFor(model => model.PercentMarkup)
            </td>
        </tr>
        <tr id="pnlPreciousMetalsFlatMarkup">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.FlatMarkup):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.FlatMarkup) [@Model.BaseCurrencyIn]
                @Html.ValidationMessageFor(model => model.FlatMarkup)
            </td>
        </tr>

        <tr id="pnlPreciousMetalsPriceRoundingType">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.PriceRoundingType):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.PriceRoundingType, ((PriceRoundingType)Model.PriceRoundingType).ToSelectList())
                @Html.ValidationMessageFor(model => model.PriceRoundingType)
            </td>
        </tr>

        <tr id="pnlPreciousMetalsPriceRounding">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.PriceRounding):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.PriceRounding)
                @Html.ValidationMessageFor(model => model.PriceRounding)
            </td>
        </tr>
    </table>
}